<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="姚德秋">
    <title></title>
    <style>
        *{
            box-sizing: border-box;
        }
        ul{
            padding: 0;
            margin: 0;
            list-style: none;
        }
    .box{
        width: 520px;
        height: 280px;
        margin: 100px auto;
        position: relative;
    }
    .img-list li{
        position: absolute;
        top: 0;
        left: 0;
        display: none;
    }
    .img-list li.current{
        display: block;
    }
    .indicator{
        width: 100%;
        position: absolute;
        left: 0;
        bottom: 0px;
        display: flex;
        justify-content: center;
        color: white;
    }
    .indicator li{
        width: 20px;
        height: 20px;
        background-color: #aaa;
        text-align: center;
        line-height: 20px;
        margin: 0 5px;
        border-radius: 50%;
        cursor: pointer;
    }
    #active{
        background-color: red;   
    }
    .img-click span{
        width: 30px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        color: white;
        background-color: rgba(0, 0, 0, 0.1);
        position: absolute;
        top:calc(50% - 20px);
        display: block;     
    }
    .img-click span:hover{
        background-color: orange;
        cursor: pointer;
    }
    .img-click .prev{
      left: 0;
    }
    .img-click .next{
        right: 0;
    }
    </style> 

</head>
<body>
    <div class="box">
        <ul class="img-list">
            <li class="current"><a href="#"><img src="01.jpg" alt=""></a></li>
            <li><a href="#"><img src="02.jpg" alt=""></a></li>
            <li><a href="#"><img src="03.jpg" alt=""></a></li>
            <li><a href="#"><img src="04.jpg" alt=""></a></li>
            <li><a href="#"><img src="05.jpg" alt=""></a></li>
        </ul>

        <ul class="indicator">
            <li id="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
        <div class="img-click">
            <span class="prev">&lt;</span>
            <span class="next">&gt;</span>
        </div>
    </div>
    <script src="./jquery.js"></script>
</body>
</html>
<script>
    $(function(){
        var index = 0;
        // 上一张
        function previmg(){
             index = 
             index==0 ? index=$('.img-list li').length-1 : index-1;
             showimg();
        }
        // 下一张
          function nextimg(){
            index = 
            index==$('.img-list li').length-1 ? 0 : index+1;
            showimg();
        }
        function showimg(){
            // console.log(index);
            $('.img-list li').eq(index).show().siblings().hide();
            $('.indicator li').eq(index).css('background-color','red').siblings().
            css('background-color','black');
        }
        // 1自动切换图片
        var timer = setInterval(nextimg,1000);
        // 2.悬停指示灯，图片跟随指示灯切换
        $('.indicator li').hover(function(){
           $(this).css('background-color','red').siblings().
           css('background-color','black').parent('.indicator').prev('.img-list').children().eq($(this).index()).show()
           .siblings().hide();   
           console.log($(this).index());},function(){
           });
        //  3.悬停box切换
        $('.box').hover(function(){
            clearInterval(timer); 
        },function(){
            timer = setInterval(nextimg,1000);
        });
      $('.prev').click(function(){
           previmg();
      });
      $('.next').click(function(){
           nextimg();
      });})
</script>